<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/7
 * Time: 23:19
 */

namespace app\admin\model;


use think\Model;

class CouponModel extends Model
{
    // 确定链接表名
    protected $name = 'coupon';

    public function getcouponList($where, $offset, $limit){
        return $this->where($where)->limit($offset, $limit)->order('id desc')->select();
    }

    public function getAllArticles($where){
        return $this->where($where)->count();
    }

    public function add($param){
        try{
            $result = $this->save($param);
            if(false === $result){
                // 验证失败 输出错误信息
                return msg(-1, '', $this->getError());
            }else{

                return msg(1, url('index'), '添加成功');
            }
        }catch (\Exception $e){
            return msg(-2, '', $e->getMessage());
        }
    }

    public function edit($param){
        try{

            $result = $this->save($param, ['id' => $param['id']]);

            if(false === $result){
                // 验证失败 输出错误信息
                return msg(-1, '', $this->getError());
            }else{

                return msg(1, url('index'), '编辑成功');
            }
        }catch(\Exception $e){
            return msg(-2, '', $e->getMessage());
        }
    }
    public function del($id){
        try{

            $this->where('id', $id)->delete();
            return msg(1, '', '删除成功');

        }catch(\Exception $e){
            return msg(-1, '', $e->getMessage());
        }
    }
    protected function getAddtimeAttr($v){
        return date('Y-m-d H:i:s',$v);
    }
    protected function getAtimeAttr($v){
        return date('Y-m-d ',$v);
    }
    protected function getBtimeAttr($v){
        return date('Y-m-d ',$v);
    }


}